package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduSchoolVacancy.EduSchoolVacancyKeyVO;
import com.jwsoft.manager.common.vo.eduSchoolVacancy.EduSchoolVacancyQueryVO;
import com.jwsoft.manager.common.vo.eduSchoolVacancy.EduSchoolVacancyVO;
import com.jwsoft.manager.common.vo.eduSchoolVacancy.SchoolVacancyFirstVO;
import com.jwsoft.manager.core.integration.EduSchoolVacancyIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 学校缺额表网关
 *
 * @author hhj
 * @since 2022-12-21
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "学校缺额表", description = "学校缺额表")
public class EduSchoolVacancyController {

    @Autowired
    public EduSchoolVacancyIntegration eduSchoolVacancyIntegration;


    @Operation(summary = "学校缺额表分页查询",description = "学校缺额表分页查询")
    @PostMapping(value = "/eduSchoolVacancy0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSchoolVacancyVO>> getList(@RequestBody @Validated EduSchoolVacancyQueryVO vo) {
        return AppResponse.successData(eduSchoolVacancyIntegration.getList(vo));
    }

    @Operation(summary = "学校缺额表根据主键查询详情",description = "学校缺额表根据主键查询详情")
    @PostMapping(value = "/eduSchoolVacancy0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVacancyVO> getById(@RequestBody @Validated EduSchoolVacancyKeyVO vo) {
        return AppResponse.successData(eduSchoolVacancyIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "学校缺额表新增",description = "学校缺额表新增")
    @PostMapping(value = "/eduSchoolVacancy0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVacancyVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduSchoolVacancyVO vo) {
        return AppResponse.successData(eduSchoolVacancyIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "学校缺额表修改",description = "学校缺额表修改")
    @PostMapping(value = "/eduSchoolVacancy0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVacancyVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduSchoolVacancyVO vo) {
        return AppResponse.successData(eduSchoolVacancyIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "学校缺额表单个删除", description = "学校缺额表单个删除")
    @PostMapping(value = "/eduSchoolVacancy0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduSchoolVacancyKeyVO vo) {
        eduSchoolVacancyIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "学校缺额表一键清除", description = "学校缺额表一键清除")
    @PostMapping(value = "/eduSchoolVacancy0009", produces = "application/json;charset=UTF-8")
    public AppResponse delAll(@RequestBody @Validated EduSchoolVacancyQueryVO vo) {
        eduSchoolVacancyIntegration.delAll(vo);
        return AppResponse.successMsg("删除成功！");
    }
    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "初始化学校缺额信息", description = "初始化学校缺额信息")
    @PostMapping(value = "/eduSchoolVacancy0007", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSchoolVacancyVO>> firstSchoolVacancyList(@RequestBody @Validated SchoolVacancyFirstVO vo) {

        return AppResponse.successData(eduSchoolVacancyIntegration.SchoolVacancyFirstList(vo));
    }

    @RequestMapping(
            value = "/eduSchoolVacancy0008",
            method = {RequestMethod.POST, RequestMethod.GET})
    @Operation(summary = "学校缺额信息导出", description = "学校缺额信息导出")
    @NoSignCrypto
    public void downloadData(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            @RequestBody(required = false) EduSchoolVacancyQueryVO vo,
            HttpServletResponse response) {

        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        eduSchoolVacancyIntegration.downloadData(vo,response);

    }



}
